<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<title>Yooes管理中心</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="/sys-admin/css/general.css" rel="stylesheet" type="text/css">
<link href="/sys-admin/css/main.css" rel="stylesheet" type="text/css">
<script src="/sys-admin/js/jquery.js" type="text/javascript"></script>
<script src="/sys-admin/js/cn_message.js" type="text/javascript"></script>
<script src="/sys-admin/js/validate.js" type="text/javascript"></script>
<script src="/sys-admin/js/common.js" type="text/javascript"></script>
<script src="/sys-admin/js/jquery.form.js" type="text/javascript"></script>
</head>
<body>
<h1>
<span class="action-span"><a href="javascript:popAddBlock(<{$channel.channel_id}>);">添加内容块</a></span>
<span class="action-span1"><{$channel.channel_name}>-内容管理</span>
</h1>
<div class="list-div">
	<table cellpadding="2" cellspacing="1" width="100%" id="h_c">
  	<tr>
    <th class="num">#</th>
    <th>块名</th>
    <th>唯一码</th>
    <th width="20%">类型</th>
    <th width="20%">操作</th>
  	</tr>
  	<{foreach from=$blocks item=block name=i}>
    <tr id="b_<{$block.block_id}>">
	<td class="num"><{$smarty.foreach.i.index+1}></td>
	<td><{$block.block_name}></td>
	<td><{$block.block_sn}></td>
	<td><{if $block.block_type == 1}>超链接<{elseif $block.block_type==2}>图片<{elseif $block.block_type==3}>产品<{/if}></td>
	<td>
	<a href="javascript:delBlock(<{$block.block_id}>);">删除</a>
	<a href="javascript:popEditBlockName(<{$block.block_id}>);">修改名称</a>
	<a href="/sys-admin/action/cms/store.php?met=storelist&bid=<{$block.block_id}>">内容管理</a>
	</td>
    </tr>
    <{/foreach}>
  	</table>
</div>
<script type="text/javascript">
function popAddBlock(channelid){
	var html ='名　称：<input type="text" maxlength="30" size="20" num="1" id="b_name" vmin="0" vmax="30">'
	 	+ '<p>唯一码：<input type="text" maxlength="30" size="20" id="b_sn" vmin="0" vmax="30"></p>'
	 	+ '<p>类　型：<select name="type" id="b_type"><option value="1">超链接</option><option value="2">图片</option><option value="3">产品</option></select></p>'
	 	+ '<input class="button" type="button" value="添加" onclick="addBlock('+channelid+');">';
	    popDailog('添加块',html,160);
}
function addBlock(channelid){
	if(!Fun.requiredLetterDigitalChineseCheck($('#b_name'))){
		alert('名称必须为中文、数字或字母');
		return;
	}
	if(!Fun.requiredwCheck($('#b_sn'))){
		alert('唯一码必须为数字、字母或_');
		return;
	}
	var name = $.trim($('#b_name').val());
	var sn = $.trim($('#b_sn').val());
	var type = $('#b_type').val();
	var url = '/sys-admin/action/cms/block.php?met=addblock'
	       +'&name='+name
	       +'&sn='+sn
	       +'&type='+type
	       +'&channelid='+channelid
	       +'&t='+(new Date().getTime());
	$.get(url,null,function(result){
		result = $.trim(result);
		var json = eval('('+result+')');
		if(json.code == 1){
			var typename='';
			switch (type) {
		        case '1':typename = '超链接';break;
		        case '2':typename = '图片';break;
		        case '3':typename = '产品';break;
		        default:;
			}
			var html='<tr id="b_'+json.id+'"><td>-</td><td>'+name+'</td><td>'+sn+'</td><td>'+typename+'</td><td>'
					+'<a href="javascript:delBlock('+json.id+');">删除</a>'
					+'<a href="javascript:popEditBlockName('+json.id+');">修改名称</a>'
					+'<a href="/sys-admin/action/cms/store.php?met=storelist&bid='+json.id+'">内容管理</a>'
					+'</td></tr>'
			$('#h_c').append(html);
			closeUpImg();
			alert('添加成功');
		}else if(json.code == 2){
			alert('唯一码已被占用');
		}else{
			alert('添加失败');
		}
	});
}

function delBlock(id){
	var name = $('#b_'+id).find('td').eq(1).html();
	if(confirm('确定要删除'+name+'?')){
		var url = '/sys-admin/action/cms/block.php?met=delblock'
		       +'&id='+id
		       +'&t='+(new Date().getTime());
		$.get(url,null,function(result){
			if($.trim(result) == "1"){
				$('#b_'+id).remove();
				alert("删除成功");
			}else{
				alert("删除失败");
			}
		});
	}
}

function popEditBlockName(id){
	var name = $.trim($('#b_'+id).find('td').eq(1).html());
	var html ='名　称：<input type="text" maxlength="30" size="20" value="'+name+'" num="1" id="b_name" vmin="0" vmax="30">'
	 	+ '<br/><input class="button" type="button" value="修改" onclick="editBlockName('+id+');">';
	    popDailog('修改名称',html,160);
}


function editBlockName(id){
	if(!Fun.requiredLetterDigitalChineseCheck($('#b_name'))){
		alert('名称必须为中文、数字或字母');
		return;
	}
	var name = $.trim($('#b_name').val());
	var url = '/sys-admin/action/cms/block.php?met=editnameblock'
	       +'&name='+name
	       +'&id='+id
	       +'&t='+(new Date().getTime());
	$.get(url,null,function(result){
		if($.trim(result) == "1"){
			$('#b_'+id).find('td').eq(1).html(name);
			closeUpImg();
			alert("修改成功");
		}else{
			alert("修改失败");
		}
	});
}

</script>
</body></html>